package com.sl.water.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.water.dao.PlanStaticDao;
import com.sl.water.entity.PlanStatic;
import com.sl.water.service.PlanStaticService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @description:
 * @author: duan
 * @time: 2025-06-27 10:41
 */
@Service
@RequiredArgsConstructor
public class PlanStaticServiceImpl extends ServiceImpl<PlanStaticDao, PlanStatic> implements PlanStaticService {
    @Override
    public Page<PlanStatic> pageList(int page, int size, String name, String fwdw, String year) {
        LambdaQueryWrapper<PlanStatic> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(name)) {
            lambdaQueryWrapper.like(PlanStatic::getName, name);
        }
        if (StringUtils.isNotEmpty(fwdw)) {
            lambdaQueryWrapper.eq(PlanStatic::getFwdw, fwdw);
        }
        if (StringUtils.isNotEmpty(year)) {
            lambdaQueryWrapper.apply("YEAR(sprq) = {0}", year);
        }
        lambdaQueryWrapper.orderByDesc(PlanStatic::getSprq);
        return this.page(new Page<>(page, size), lambdaQueryWrapper);
    }
}
